package com.yxhl.km.module.utils;

import android.view.Gravity;
import android.widget.Toast;

import com.yxhl.km.MyApplication;

/**
 * 张亚楠 on 2017/10/30.
 */

public class ToastUtil {

    private static Toast mTempToast = null;

    /**
     * @param str 待弹出String
     * @param
     * @author zhang
     */
    public static void makeToast(String str, boolean isLong) {

        int duration = 0;

        if (isLong) {

            duration = Toast.LENGTH_SHORT;
        } else {

            duration = Toast.LENGTH_LONG;
        }

        if (mTempToast == null) {
            mTempToast = Toast.makeText(MyApplication.mContext, str, duration);
        } else {

            mTempToast.setText(str);
        }

        mTempToast.setGravity(Gravity.CENTER, 0, 0);
        mTempToast.show();
    }

    /**
     * @param str 待弹出String
     * @param
     * @author zhang
     */
    public static void makeToast(String str) {
        int duration = Toast.LENGTH_SHORT;
        if (mTempToast == null) {
            mTempToast = Toast.makeText(MyApplication.mContext, str, duration);
        } else {

            mTempToast.setText(str);
        }

        mTempToast.setGravity(Gravity.CENTER, 0, 0);
        mTempToast.show();
    }

    public static void debugToast(String str, boolean isLong) {
        if (Constants.LOGDEBUG) {
            int duration = 0;
            if (isLong) {
                duration = Toast.LENGTH_LONG;
            } else {
                duration = Toast.LENGTH_SHORT;

            }
            if (mTempToast == null) {

                mTempToast = Toast.makeText(MyApplication.mContext, str, Toast.LENGTH_SHORT);
            } else {
                mTempToast.setText(str);
            }
            mTempToast.show();
        }
    }
    /**
     * 只debug模式下显示
     *
     * @param str
     * @param
     * @author Jooper
     * @2016年7月3日 下午6:10:50
     */
//    public static void debugToast(String str, boolean isShort) {
//
//        int duration = 0;
//
//        if (isShort) {
//
//            duration = Toast.LENGTH_SHORT;
//        } else {
//
//            duration = Toast.LENGTH_LONG;
//        }
//
//        if (Constants.LOGDEBUG) {
//
//            if (mTempToast == null) {
//
//                mTempToast = Toast.makeText(MyApplication.mContext, str, duration);
//            } else {
//
//                mTempToast.setText(str);
//            }
//            mTempToast.show();
//        }
//    }
}